package action;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import persistency.PersistencyException;
import persistency.Price_CRUD;
import persistency.Product_CRUD;
import model.Price;
import model.Product;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterPrice extends ActionSupport {
	
	
	private String naam;
	

	private Price priceBean;
	private Price_CRUD crud = new Price_CRUD();
	private Product_CRUD prodCrud = new Product_CRUD();
	private List<String> active;
	private HashSet<String> unitCode;
	private List unitCodeList;
	private List <Integer> priceIdList;
	private List <String> priceId;
	
	
	public List<String> getPriceId() {
		return priceId;
	}

	public void setPriceId(List<String> priceId) {
		this.priceId = priceId;
	}

	private HashSet<String> produkten;
	private String selectedActive;
	private String selectedUnitCode;
	private String selectedProduct;
	
	
	public List<Integer> getPriceIdList() {
		return priceIdList;
	}

	public void setPriceIdList(List<Integer> priceIdList) {
		this.priceIdList = priceIdList;
	}

	public String getNaam() {
		return naam;
	}

	public void setNaam(String naam) {
		this.naam = naam;
	}

	public List getUnitCodeList() {
		return unitCodeList;
	}

	public void setUnitCodeList(List unitCodeList) {
		this.unitCodeList = unitCodeList;
	}

	public String getSelectedUnitCode() {
		return selectedUnitCode;
	}

	public void setSelectedUnitCode(String selectedUnitCode) {
		this.selectedUnitCode = selectedUnitCode;
	}

	public String getSelectedProduct() {
		return selectedProduct;
	}

	public void setSelectedProduct(String selectedProduct) {
		this.selectedProduct = selectedProduct;
	}

	public String getSelectedActive() {
		return selectedActive;
	}

	public void setSelectedActive(String selectedActive) {
		this.selectedActive = selectedActive;
	}

	public HashSet<String> getProdukten() {
		return produkten;
	}

	public void setProdukten(HashSet<String> produkten) {
		this.produkten = produkten;
	}
	
	public HashSet<String> getUnitCode() {
		return unitCode;
	}

	public void setUnitCode(HashSet<String> unitCode) {
		this.unitCode = unitCode;
	}
	
	public List<String> getActive(){
	    return active;
	}
	
	public void setActive(List<String> active) {
		this.active = active;
	}


	public Price getPriceBean() {
		return priceBean;
	}
	
	public void setPriceBean(Price price) {
		priceBean = price;
	}
	
	public String getDefaultActive(){
		return "true";
	}
	
	public String getDefaultUnitCode(){
		return "stuk";
	}
	
	public String getDefaultProduct(){
		return "1";
	}
	
	public RegisterPrice() throws PersistencyException{
		
	}
	
	@Override
	public String execute() throws Exception {
		
		active = new ArrayList<String>();
		unitCode = new HashSet<String>();
	    produkten = new HashSet<String>();
	    priceId = new ArrayList<String>();
	    
	    try{
	    	naam = (Calendar.getInstance().getTime()).toString();
	    	
		    active.add("true");
		    active.add("false");
		    
		    
		    unitCodeList = crud.getAllUnitCodes();
		    for(Object p : unitCodeList){
		    	unitCode.add(p.toString());
		    } 
		    
		    priceIdList = crud.getAllPriceId();
		    for(int p: priceIdList){
		    	priceId.add(Integer.toString(p));
		    }
		    	
		   
		    for (Product p : prodCrud.getAll()){
		    	produkten.add(Long.toString(p.getProductId()));
		    	
		    }	
		}catch (PersistencyException e){
			e.printStackTrace();
		}
		
		//call Service class to store priceBean's state in database
		//hier moet het submitten van de informatie naar de DB gebeuren.
		//crud.insert(priceBean);
		System.out.println(active.toString());
		System.out.println(unitCode.toString());
		System.out.println(produkten.toString());
		System.out.println(priceId.toString());
		return "SUCCESS";
		
	}
}